home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Hardware / Misc. Tools / LFSR Verilog CAD Tool / Horiz Count next >
Encoding:
Text File  |  1993-06-03  |  3.1 KB  |  120 lines  |  [TEXT/OIUB]

  1. `timescale 1 ns / 100 ps
  2. /* Linear Feedback Shift Register 
  3.  * verilog module "HCOUNT"
  4.  * Generated by Macintosh application 'LFSR' 5/17/93 1:30 PM 
  5.  * company: Apple Computer 
  6.  * project: Display Controller 
  7.  * designer: Elmer Fudd
  8.  * prototypes:
  9.    HCOUNT(clk, preset, Q, NewLine);
  10.    HCOUNT(.clk(CLOCK), .preset(PRESET), .Q(Q), .NewLine(TC));
  11.  *
  12.  * The counter reaches terminal count after 640 positive edge clocks. 
  13.  * 'NewLine' is asserted high at the end of count.
  14.  * count is preset synchronously by an active low on 'preset'.
  15.  * The counter is free running. It presets itself on every terminal count. 
  16.  * The shift register output of the counter is brought out of the module as 'Q'.
  17.  * The counter uses AND (or NAND) gates on the output of the shift register to detect for terminal count of all 'ones'.
  18.  * The main counter consist of 10 registers with 2 taps feedback to the input. 
  19.  */
  20. module HCOUNT (clk, preset, Q, NewLine);
  21. input clk;  
  22. input preset; 
  23. output NewLine; 
  24. output Q;
  25. reg [9:0] D;
  26. reg  [9:0] Q;
  27.  
  28. assign NewLine = &Q; 
  29.  
  30. always @(Q or preset or NewLine)
  31.     begin
  32.         casex ({preset, NewLine}) // synopsys parallel_case full_case
  33.             'b0?,            // preset to value
  34.             'b?1:            // retrigger presets from TC
  35.                 begin
  36.                     D = 'h139; // preset to seed
  37.                 end
  38.             'b10:           // normal counting
  39.                 begin
  40.                     D[9:1] = Q[8:0];
  41.                     D[0] = Q[9] ^ Q[2];
  42.                 end
  43.         endcase
  44.     end // always
  45.     
  46. // Shift register description
  47. always @(posedge clk)
  48.     begin
  49.         Q = D;     // make into D register
  50.     end
  51. endmodule // HCOUNT
  52.  
  53. // synopsys translate_off
  54. module LFSR_Test_Counter(clock, ce, preset, tc);
  55. input clock;
  56. input ce;
  57. input preset;
  58. output tc;
  59. reg [31:0] count;
  60.  
  61. assign tc = ~(count == 0);
  62.  
  63. always @(posedge clock)
  64.     begin
  65.         if(preset == 0 || count == 0)
  66.             begin
  67.                 count = 639;
  68.             end
  69.         else if(ce && count >= 0)
  70.             begin
  71.                 count = count - 1;
  72.             end
  73.     end
  74. endmodule // LFSR_Test_Counter
  75. /* The Test module compares the LFSR counter with a conventional decrement counter
  76.  * any discrepancy between the two counters will be displayed
  77.  * The number of clocks to terminal count is always displayed
  78.  */
  79. module Test_HCOUNT;
  80.  
  81. reg clock;
  82. reg enable;
  83. reg ce;
  84. reg [9:0] Q;
  85. integer i;
  86. HCOUNT T0(clock, enable, Q, tc);
  87. LFSR_Test_Counter T1(clock, ce, enable, tc2);
  88. initial
  89.     begin
  90.         i = 0;
  91.         clock = 0;
  92.         ce = 1;
  93.         enable = 0;
  94.         #100
  95.         enable = 1; 
  96.         #204600
  97.         $finish;
  98.     end
  99. always
  100.     begin
  101.         #50
  102.         clock = ~clock;
  103.     end
  104. always @(posedge clock)
  105.     begin
  106.          if(tc == 1)
  107.             begin
  108.                 $display("Terminal count occurs at clock #%d", i);
  109.             end
  110.         if(tc != tc2)
  111.             begin
  112.                 $display("Discrepancy between LFSR counter and test counter at clock #%d", i);
  113.                 $display("LFSR terminal count %b, Test terminal count %b",tc, tc2);
  114.             end
  115. // $display("%d - ce %b, preset %b ,tc %b, test tc %b, Q %x", i, ce, enable, tc, tc2, Q);
  116.         if(ce) i = i + 1;
  117.     end
  118. endModule // Test_HCOUNT
  119. // synopsys translate_on
  120.